package com.source.lightfowl.syslog.service.Impl;

import com.source.lightfowl.syslog.dao.OperationDao;
import com.source.lightfowl.syslog.pojo.Operation;
import com.source.lightfowl.syslog.service.OperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @Author: 谢春泳
 * @Description:
 * @Date: 2020/2/25 23:37
 */
@Service
public class OperationServiceImpl implements OperationService{
    @Autowired
    private OperationDao operationDao;

    @Override
    public void save(Operation log) {
        operationDao.save(log);
    }

    @Override
    public void deleteById(String id) {
        operationDao.deleteById(id);
    }

    @Override
    public void deleteByIds(String ids) {
        String[] strings = ids.split(",");//用英文逗号分开字符串
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i <strings.length ; i++) {
            list.add(strings[i]);
        }
        operationDao.deleteBatch(list);
    }

    @Override
    public Optional<Operation> findById(String id) {
        return operationDao.findById(id);
    }

    @Override
    public List<Operation> findAll() {
        return operationDao.findAll();


    }

    @Override
    public Page<Operation> findAllPage(int page, int pageNum) {
        return operationDao.findAll(PageRequest.of(page-1,pageNum));
    }

    @Override
    public List<Operation> findByPersonId(String id) {
        return operationDao.findByPersonId(id);
    }
}
